import matplotlib.pyplot as plt
import numpy as np
import json
import matplotlib.font_manager as font_manager
import pandas as pd
import logging

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(levelname)s: %(message)s')
with open('work/stars_info.json', 'r', encoding='UTF-8') as file:
    json_arry = json.loads(file.read())
# 绘制选手体重分布饼装图
weights = []
counts = []
for star in json_arry:
    if 'weight' in dict(star).keys():
        weight = float(star['weight'][0:2])
        weights.append(weight)
print(weights)

size_list = []
count_list = []
size1 = 0
size2 = 0
size3 = 0
size4 = 0
for weight in weights:
    if weight <= 45:
        size1 += 1
    elif 45 < weight <= 50:
        size2 += 1
    elif 50 < weight <= 55:
        size3 += 1
    else:
        size4 += 1
labels = '<=45kg', '45-50kg', '50-55kg', '>55kg'
sizes = [size1, size2, size3, size4]
explode = (0.2, 0.1, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
ax1.axis('equal')
plt.title('''《乘风破浪的姐姐》参赛嘉宾体重分布饼状图''', fontsize=18)
plt.savefig('./work/result/pie_result02.jpg')
plt.show()
